package com.dylan.elasticsearch.entity;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author dylan
 * @description 员工
 * @date 2023-03-30
 */
@Entity
@Data
@Table(name = "employee")
@EntityListeners(AuditingEntityListener.class)
@Document(indexName = "search.depart", shards = 2, replicas = 2)
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 唯一主键
     */
    @Id
    @org.springframework.data.annotation.Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Integer id;

    /**
     * 账号
     */
    @Column(name = "username")
    @Field(type = FieldType.Text)
    private String username;

    /**
     * 密码
     */
    @Column(name = "password")
    private String password;

    /**
     * 昵称
     */
    @Column(name = "nick_name")
    @Field(type = FieldType.Text)
    private String nickName;

    /**
     * 喜好
     */
    @Column(name = "enjoy")
    @Field(type = FieldType.Text)
    private String enjoy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time")
    @Field(type = FieldType.Date,
            format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss"
    )
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "modify_time")
    @Field(type = FieldType.Date,
            format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss"
    )
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date modifyTime;

    /**
     * 年龄
     */
    @Column(name = "age")
    private Integer age;

}
